﻿using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace SSN.WebFramework
{
    public class AuthService : System.Web.Services.WebService
    {
        public UserManager UserManager { get; private set; }
        public SecurityManager SecurityManager { get; private set; }
        public ParameterManager ParameterManager { get; private set; }

        public AuthService()
        {
            SecurityManager = new SecurityManager(Session);
            if (!SecurityManager.IsLoggedIn)
            {
                Context.Response.Clear();
                Context.Response.Write("{d: {'LOGOUT', true} }");
                Context.Response.Close();
                return;
            }
            ParameterManager = new ParameterManager(SecurityManager, Server, Context.Request.QueryString);
            UserManager = new UserManager(SecurityManager.SecurityContext);
        }

        /// <summary>
        /// Decrypts the provided parameter string for secure extraction of parameters.
        /// </summary>
        /// <param name="queryParam"></param>
        public void DecryptEncryptedParameterString(string queryParam)
        {
            ParameterManager = new ParameterManager(SecurityManager, Server, queryParam);
        }
    }
}